package com.gitee.cui.server.processor;


import com.gitee.cui.server.server.ServerSession;
import io.netty.channel.Channel;
import org.apache.commons.lang.StringUtils;

/**
 * serverProcessor实现抽象类
 * @author cuiqingqiang
 * @version 1.0
 * @date 2021/10/28 9:35
 **/
public abstract class AbstractServerProcessor implements ServerProcessor {

    protected String getKey(Channel channel) {
        return channel.attr(ServerSession.KEY_USER_ID).get();
    }

    protected void setKey(Channel channel, String key) {
        channel.attr(ServerSession.KEY_USER_ID).set(key);
    }

    protected void checkAuth(Channel channel) throws Exception {
        if (StringUtils.isBlank(getKey(channel))) {
            throw new Exception("此用户，没有登录成功");
        }
    }
}
